import sys
from core.document import OFDFile

import os
import shutil

doc = OFDFile(sys.argv[1])
paths = doc.draw_document()  
#doc.remove_unused_resources()
#print(paths)
if len(sys.argv) < 2:
    target_path = os.path.dirname(sys.argv[1])
else:
    target_path = sys.argv[2]
if not os.path.exists(target_path):
    os.makedirs(target_path)
    print(f'Created directory: {target_path}')
for path in paths:
    if os.path.dirname(sys.argv[1]) == target_path:
        continue
    sourcefile = os.path.join(os.curdir, path)
    targetfile = os.path.join(target_path, os.path.basename(path))
    shutil.move(sourcefile, targetfile)
    print(f'Moved {sourcefile} to {targetfile}')